define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(document).on('click', '.btn-complate', function () {
                // var value = $('#submit_t').data('data-id');
                var idValue = $('#submit_t').attr('data-id');
                console.log(idValue);
                layer.confirm('确定出票完成？', {
                    btn: ['确定', '取消']
                }, function (index) {
                    $.ajax({
                        type: 'POST',
                        url: "/a.php/order/update_order_status",
                        data: {
                            'order_id': idValue,
                        },
                        success:function (index) {
                            //layer.close(layer.index);
                            layer.close(layer.index);
                            $(".btn-refresh").trigger("click");
                        }

                    });
                }, function () {

                });

            });
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ticket/index' + location.search,
                    // start_url: 'order/update_order_status' + location.search,
                    // add_url: 'ticket/add',
                    // edit_url: 'ticket/edit',
                    // del_url: 'ticket/del',
                    // multi_url: 'ticket/multi',
                    // import_url: 'ticket/import',
                    // complate_url: 'order/update_order_status',
                    table: 'order_ticket',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        // {field: 'schedule_id', title: __('Schedule_id'),operate:false},
                        // {field: 'order_id', title: __('Order_id'),operate:false},
                        // {field: 'user_id', title: __('User_id'),operate:false},
                        // {field: 'film_info_id', title: __('Film_info_id'),operate:false},
                        // {field: 'hall_id', title: __('Hall_id'),operate:false},
                        {field: 'seat_price', title: __('Seat_price'), operate:false},
                        {field: 'seat_type', title: __('Seat_type'), operate:false, searchList: {"normal":__('普通座'),"comfortable":__('舒适座')}, formatter: Table.api.formatter.status},
                        {field: 'row_num', title: __('排'),operate:false},
                        {field: 'column_num', title: __('座'),operate:false},
                        {field: 'status', title: __('Status'), operate:false, searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons:[
                                {
                                    name:'ticket',
                                    text:__('打印小票'),
                                    icon:'fa fa-log',
                                    classname:'btn btn-xs btn-success btn-dialog',
                                    extend: 'data-area=\'["80%","80%"]\'',
                                    // confirm:"点击打印后订单会变成已完成,确定要打印吗？",
                                    hidden:function (row)
                                    {
                                        if(row.status=='-1' || row.status=='0' || row.status=='2'|| row.status=='3')
                                        {
                                            return true;
                                        }
                                    },
                                    url:function (row,column) {
                                        return 'ticket/print/?ticket_id='+row.id
                                    },
                                    refresh:true,
                                },

                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        complate: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
